{extend name="admin@public/basic" /}
{block name="style"}{/block}
<link rel="stylesheet" href="__STATIC__/css/admin/public.css" media="all"/>
{block name="cotent"}
<form class="layui-form" style="width:80%;">
    <br>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">用户头像</label>
        <div class="layui-input-block" id="upload_image_div">
            <input type="hidden" id="head_img" value="{$user.head_img|default=''}">
            <div class="uploadimage" data-upload-image="one" data-upload-id="head_img" data-upload-div="upload_image_div" style="background-image: url(__STATIC__/image/admin/upload.png);">
            </div>
        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">管理账号</label>
        <div class="layui-input-block">
            <input type="text" id="username" class="layui-input username" lay-verify="required" value="{$user.username|default=''}" placeholder="请输入管理账号">
        </div>
    </div>

    {if empty($user)}
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">初始密码</label>
        <div class="layui-input-block">
            <input type="password" id="password" class="layui-input password" lay-verify="required" placeholder="请输入初始密码">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-block">
            <input type="password" id="password1" class="layui-input password1" lay-verify="required" placeholder="请输入确认密码">
        </div>
    </div>
    {/if}

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">手机</label>
        <div class="layui-input-block">
            <input type="text" id="phone" class="layui-input phone" value="{$user.phone|default=''}" placeholder="请输入手机">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">QQ</label>
        <div class="layui-input-block">
            <input type="text" id="qq" class="layui-input qq" value="{$user.qq|default=''}" placeholder="请输入QQ">
        </div>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" id="mail" class="layui-input mail" value="{$user.mail|default=''}" placeholder="请输入邮箱">
        </div>
    </div>


    <div class="layui-form-item layui-row">
        <label class="layui-form-label">用户权限</label>
        <div class="layui-input-block">
            {foreach auth as $vo}
            <input type="checkbox" id="auth_id" name="auth_id" class="layui-input auth_id" value="{$vo.id|default=''}" lay-skin="primary" title="{$vo.title|default=''}" {eq name='$vo.is_checked|default=false' value='true' }checked{/eq}>
            {/foreach}

        </div>
    </div>

    <div class="layui-form-item layui-row layui-col-xs12">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入备注信息" id="remark" class="layui-textarea remark">{$user.remark|default=''}</textarea>
        </div>
    </div>

    {if !empty($user)}
    <input type="hidden" class="id" id="id" value="{$user.id|default=''}">
    {/if}

    <div class="layui-form-item layui-row layui-col-xs12">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-sm" id="submitBtn">提交</button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" data-close="closeOpen">取消</button>
        </div>
    </div>
</form>
{/block}

{block name="script"}
<script>

    /**
     * 上传图片处理
     */
    $.form.imageRender('upload_image_div', 'one');

    /**
     * 添加、编辑
     */
    $("#submitBtn").on("click", function () {
        auth_id = [];
        $("input:checkbox[name='auth_id']:checked").each(function () {
            auth_id.push($(this).val());
        });
        var url = "{if empty($user)}{:url('@admin/user/add')}{else/}{:url('@admin/user/edit')}{/if}";
        var data = {
            id: $("#id").val(),
            head_img: $("#head_img").val(),
            username: $("#username").val(),
            password: $("#password").val(),
            password1: $("#password1").val(),
            phone: $("#phone").val(),
            qq: $("#qq").val(),
            mail: $("#mail").val(),
            auth_id: auth_id,
            remark: $("#remark").val(),
        };
        $.request.post(url, data, function (res) {
            $.msg.success(res.msg, function () {
                $.tool.reload('open');
            })
        })
        return false;
    });
</script>
{/block}
